#include <cstdio>
char map[12] = "10X98765432";
int main()
{
    int num;
    scanf("%d", &num);
    int count = 0; //记录非法校验码的个数
    char str[19] = {0};
    int i;
    int weight[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    int sum; //记录权重和，用于计算校验和
    int Z;//用于求余
    while (num--)
    {//循环读取，同时进行判断
        sum = 0;
        scanf("%s", str);
        for (i = 0; i < 17; ++i)
        {
            if (str[i] >= '0' && str[i] <= '9')
            {
                sum += weight[i] * (str[i] - '0');
            }
            else
            {
                break;
            }
        }
        if (i < 17)
        {//这里判断是否合法
            ++count;
            printf("%s\n", str);
        }
        else
        {
            Z = sum % 11;
            if (map[Z] != str[17])
            {
                ++count;
                printf("%s\n",str);
            }
        }
    }
    if(0==count)
    {
        printf("All passed\n");
    }
    return 0;
}
